//变量引进
var accessId = getParameter("x-access-id");
var accessToken = getParameter("x-access-token");
var customerId = getParameter("customerId");
var ua = "h5";

/*ajax调用*/
function jsonAjax(url,type,data,callback) {
    $.ajax({
        url:url,
        type: type,
        contentType:"application/json",
        dataType:'json',
        async:false,
        data:data,
        headers:{
            "x-access-id": accessId,
            "x-access-token": accessToken,
            "x-ua": ua
        },
        success: callback
    });
}
/*初始化*/
$(function () {
    /*个人分享页*/
    personal();
});
/*个人主页*/
function personal() {
    var data={
        "customerId":customerId
    };
    jsonAjax(genUrl("/h5/customer/getCustomerHome"),'GET',data,personfun);
}
function personfun(res){
    if(res.code==0) {
        var data = res.data;
        // 昵称
        $(".nickName").html(data.nickName);
        /*相册渲染*/
        var alums = data.photoUrls.imgUrls;
        if (alums) {
            var alumsT = "";
            for (var i = 0; i < alums.length; i++) {
                alumsT += '<div class="swiper-slide"><img src="' + alums[i] + '" alt=""></div>';
            }
            $("#alum").append(alumsT);
        }
        // 性别以及年龄
        if (data.sexType == 0) {
            $("#sex").html("<s></s>" + data.age + "岁");
        } else if (data.sexType == 1) {
            $("#sex").html("男" + data.age + "岁");
        }
        /*当前城市和粉丝数量*/
        $("#city").html("<span><s></s>"+data.currentCity+"</span><b>粉丝数："+data.fanCount+"</b> " );
        // 花言号和聊天价格
        $(".desc2").html("美说号：" + customerId)
        $(".desc2").html("<span>花言号："+customerId+"</span><span>聊天价格："+data.videoCollectFees+"花粉/分钟</span>")
        /*收到礼物*/
        var giftlist=data.receiveGift.imgUrls;
        var giftCountstr="收到礼物 (" + data.receiveGiftCount + ")";
        itemCon(giftlist,"#giftcount",giftCountstr,"她还未收到礼物","#gift")

        // 她的真爱
        var loves = "";
        var loveListDto = data.loveListDto.customerCommonViewDtoList;
        console.log(loveListDto)
        $("#lovecount").html("她的真爱 (" + data.loveListDto.total + ")");
        var len = "";
        if (loveListDto.length == 0) {
            $("#love").html("<li class='nosomething'>快去向她表达爱意吧！</li>");
        } else if (loveListDto.length > 5) {
            len = 5;
        } else {
            len = loveListDto.length;
        }
        for (var i = 0; i < len; i++) {
            var lovepic = loveListDto[i].photo;
            console.log(lovepic)
            loves += '<li><img src="' + lovepic + '" alt=""></li>'
        }
        $("#love").append(loves);

        // 她是守护
        var guards = "";
        var watchListDto = data.watchListDto.customerCommonViewDtoList;
        $("#guardcount").html("她的守护 (" + data.watchListDto.total + ")");
        var len = "";
        if (watchListDto.length == 0) {
            $("#guardcount").html("<li class='nosomething'>快去向她表达爱意吧！</li>");
        } else if (watchListDto.length > 5) {
            len = 5;
        } else {
            len = watchListDto.length;
        }
        for (var i = 0; i < len; i++) {
            var guardspic = watchListDto[i].photo;
            guards += '<li><img src="' + guardspic + '" alt=""></li>'
        }
        $("#guard").append(guards);

        // 动态
        var dynamicimg = data.newDynamic.imgUrl;
        if(dynamicimg){
            $("#dynamic").html('<li><img src="' + dynamicimg + '" alt=""></li>');
        }else{
            $("#dynamic").html("<li class='nosomething'>她还没有发布过动态</li>");
        }
        // 送出的礼物
        var sendGift = data.sendGift.imgUrls;
        var giftCountstr="送出礼物 (" + data.sendGiftCount + ")";
        itemCon(sendGift,"#giftoutcount",giftCountstr,"她还没送出过礼物","#giftout")
        // 她的访客
        var visitList=data.visitList.imgUrls;
        var visittit="她的访客";
        itemCon(visitList,".info-seeher>h2",visittit,"还没有人看过她","#dysee")
        /*聊天能力*/
        var chatlist = data.chatTheme.chatTheme;
        var chat = "";
        if(!chatlist){
            $("#chatTheme").html("ta还没设置聊天能力");
        }else{
            for (var i = 0; i < chatlist.length; i++) {
                chat += '<li>' + chatlist[i] + '</li>';
            }
            $("#chatTheme").append(chat);
        }
    }
}
function itemCon(list,countele,str,str2,elelist) {
    var items = "";
    $(countele).html(str);
    var len = "";
    if (list.length == 0) {
        $(elelist).html("<li class='nosomething'>"+str2+"</li>");
    } else if (list.length > 5) {
        len = 5;
    } else {
        len = list.length;
    }
    for (var i = 0; i < len; i++) {
        var itemstr = list[i];
        items += '<li><img src="' + itemstr + '" alt=""></li>'
    }
    $(elelist).append(items);
}









